// 列表 产品单个展示
var basePage = require('../../../common/BasePage');
Component({
  behaviors: [basePage],
  /**
   * 组件的属性列表
   */
  properties: {
    data: Object, //外部传入产品数据
    isdescribe:{
        type:Boolean,
        value:false
    },
    whType:{
      type:String,
      value:"flower"
    },//pindan分仓拼单 flower交易大厅
    showSupplierId:{
        type:Boolean,
        value:false 
    },
    showchanggou:{
        type:Boolean,
        value:false 
    },
    showstate:{
        type:Boolean,
        value:false 
    },
    whId:{
        type:Number,
        value:1
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    /**产品数据 */
    pdc: {},
    showDetail:false
  },
  observers: {
    data: function (value) {
      // console.log("data", value);
      this.setData({
        pdc: value
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 派发加入购物车事件
     */
    add_cart_click(){
      this.triggerEvent('addCart', this.data.pdc) 
    },
    // 加入常购
    add_changgou(){
        // this.triggerEvent('addChanggou', this.data.pdc) 
        var item=this.data.pdc
        this.request({
            url: this.data.host + '/home/often/addToOften',
            data: {
                pid:item.pid
            },
            loadingTip: '正在提交',
            method: "post"
        }, this.add_often_ok);
    },
    add_often_ok(res) {
        wx.showModal({
            cancelText: '继续添加',
            confirmText: '常购清单',
            content: '是否前往常购清单',
            showCancel: true,
            title: '设置成功',
            success: (result) => {
                if (result.confirm) {
                    // console.log("跳转完善页面");
                    wx.navigateTo({
                        url: '/pages/cls/often/List',
                    })
                }
            },
        })
    },
    /**
     *点击卖家标题事件，有基地视频的话，播放视频
     */
    supplier_click() {
      this.data.data.supplier.base_video?this.triggerEvent('video', this.data.data.supplier.base_video) :'';
    },
	catch(){},
    /**
     * 收藏按钮点击
     */
    collect_click(){
      this.triggerEvent('collect', this.data.pdc)
    },
    img_click(e){
      console.log("photos",this.data.pdc.photo_list);
    },
    comment_click(){
       console.log("评论点击", this.data.pdc);
      let pdc= this.data.pdc;
      if(!pdc.comments){
      return wx.showToast({
          title: '该产品暂无评论',
          icon:'none'
        })
      }
      ///home/supplier/comment?supplier_id=1&pid=3
      wx.navigateTo({
        url: '/pages/cls/evaluat/evaluat?supplier_id='+pdc.supplier_id+"&pid="+pdc.pid,
      })
    },
    intro_click() {
      this.setData({showDetail:!this.data.showDetail})
      // console.log("intro_click");
    },
	//跳转详情
	to_detail(){
        console.log("this.data.whType",this.data.whType);
        console.log("this.data.whId",this.data.whId);
        // this.triggerEvent('toDetail', this.data.pdc)
        var whId=this.data.pdc.wh_id
        if(this.data.whType== "pindan"){
            whId=this.data.whId
        }
		wx.navigateTo({
			url: '/pages/goodsDetail/goodsDetail?pid='+this.data.pdc.pid+"&supplier_id="+this.data.pdc.supplier_id+"&from=flower"+"&whType="+this.data.whType+"&wh_id="+whId
		})
	}
  }
})